package com.flot.yazb.model.user;

import com.flot.yazb.base.model.BModel;
import com.flot.yazb.base.client.RetrofitFactory;
import com.flot.yazb.aop.stub.HeaderConfig;
import com.flot.yazb.aop.stub.RMCallback;
import com.flot.yazb.aop.stub.RMResponse;
import com.flot.yazb.retrofit.service.BService;
import com.flot.yazb.widget.utils.TimeUtils;

import java.io.Serializable;


/**
 * Created by Chexiangjia-MAC on 17/6/30.
 */

public class UserModel extends BModel implements Serializable {


    public static void getUserMsg(String id, final Transit<UserModel> incubator) {
        RetrofitFactory.getInstance()
                .create(BService.UserService.class)
                .getUserMsg(id)
                .enqueue(new RMCallback<RMResponse<UserModel>>(incubator.getContext()) {
                    @Override
                    protected void onSuccess(RMResponse<UserModel> result) {
                        HeaderConfig.instance().token = result.content.accessToken;
                        incubator.onBorn(result.content, result.code(), result.message());
                    }

                    @Override
                    protected void onFail(String errorCode, String errorInfo) {
                        incubator.onBorn(null, errorCode, errorInfo);
                    }
                });
    }


    public String accessToken = "";
    public String id = "";
    public String nicheng = "";
    public String avatar = "";
    public String mobile = "";
    public String beizhu = "";
    public String sex = "";
    public String status = "";
    public String brith = "";
    public String province = "";
    public String city = "";
    public String credit = "";
    public String baoyue = "";
    public String shouxin = "";
    public String type = "";
    public String parentid = "";
    public long vip;
    public String createtime = "";
    public int age = 0;
    public String rank = "1";

    public long getVip() {
        return vip;
    }

    public boolean getIsVip() {
        if ((System.currentTimeMillis() / 1000) > getVip()) {
            return false;
        }
        return true;
    }

    public String isBaoyue() {
        if ("0".equals(baoyue) || null == baoyue) {
            return "开通";
        }
        TimeUtils.formatPhotoDate(baoyue);
        return baoyue;
    }


}
